package Array;
/*
    贪心算法 找零
    time 2021.6.10
 */

public class GiveChange {
    public static boolean giveChange(int[] fills){
        int five=0,ten=0;
        for (int bill:fills){
            if (bill==5){
                five++;
            }else if (bill == 10){
                if (five == 0) {
                    return false;
                }
                five--;
                ten++;

            }else {
                if (five>0 && ten>0){
                    five--;
                    ten--;
                }else if (five>=3){
                    five -=3;
                }else {
                    return false;
                }
            }
        }
        return true;
    }

    public static void main(String[] args) {
        int[] nums = {5,10,5,20};
        System.out.println(giveChange(nums));
    }
}
